﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media;

namespace WpfApp6.Converter
{
    public class AgeToBrushConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            //默认画刷
            SolidColorBrush brush = Brushes.White;
            if (value != null && int.TryParse(value.ToString(), out int age))
            {
                brush = age <= 10 ? Brushes.Red
                    : age <= 20 ? Brushes.Green
                    : age <= 30 ? Brushes.Blue
                    : age <= 40 ? Brushes.Yellow
                    : age <= 50 ? Brushes.Orange 
                    : age <= 60 ? Brushes.Purple : Brushes.Brown;
            }
            return brush;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
